#!/bin/sh

host="cq01-game-dubiweb00.cq01.baidu.com st01-game-dubiweb00.st01.baidu.com"
log_path="/home/work/nginx/logs/pipedir"


if [[ $# -eq 2 ]];then
	yyyyMMdd=$1
	HH=$2
elif [[ $# -eq 0 ]];then
	yyyyMMdd=$(date "+%Y%m%d")
	HH=$(date "+%H" -d "-1 hours")
fi

local_path="/home/hadoop/bigdata/flume/default/dianquan_log"
cd $local_path

source /home/hadoop/.bashrc
phone='13426082139 13811063282 13261676918 13520011291'
phone='13811063282'
function sendMsg(){
	for number in $phone
	do
		echo "$1 failed"
		gsmsend-script $number@"$1 failed"
	done
}

for h in ${host[@]};do
	cashier=${h}
	log_name=dianquan_access.log.${yyyyMMdd}$HH
	{
		rm -rf ${cashier}_$log_name*
		wget -c -t 0 --limit-rate 15M ftp://${h}${log_path}/$log_name -O ${cashier}_$log_name && 
		gzip ${cashier}_$log_name &&
		$(hdfs dfs -mkdir -p /flume/events/dianquan/nginx-collector/$yyyyMMdd/${HH}00/17/)
		$(hdfs dfs -put ${cashier}_${log_name}.gz /flume/events/dianquan/nginx-collector/$yyyyMMdd/${HH}00/17/)
		if [[ $? -ne 0 ]];then
			sendMsg "${hostname} upload ${log_name}"
		fi
	} &
done
wait

find ./ -ctime +5 -name "*dianquan_access.log*" -exec rm {} \;
